<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let loginList = [
            { userName: 'admin', password: 'admin321' },
            { userName: 'zhangsan', password: 'zs321' },
            { userName: 'lisi', password: 'ls321' },  
            { userName: 'yyqx', password: 'yyqx321' }
        ]
        let userInfo = {
            token1: {
                city: '杭州',
                money: '1000w',
                sex: '女',
                userName: 'admin',
                password: 'admin321'
            },
            token2: {
                city: '北京',
                money: '1100w',
                sex: '女',
                userName: 'zhangsan',
                password: 'zs321'
            },
            token3: {
                city: '北京',
                money: '800w',
                sex: '男',
                userName: 'lisi',
                password: 'ls321'
            },
            token4: {
                city: '天津',
                money: '600w',
                sex: '男',
                userName: 'yyqx',
                password: 'yyqx321'
            }
        }

        function fn(a, b) {
        const num1 = prompt('请输入用户名')
        const num2 = prompt('请输入用户密码')
        let arr = []
        const random = String(Math.floor(Math.random() * 4))
        for (let k in userInfo) {
          arr.push(userInfo[k])
        }
        for (let i = 1; i < arr.length; i++) {
          delete arr[i].password
          arr[i].userName = num1
        }
        for (let i = 0; i < a.length; i++) {
          if (num1 === a[i].userName && num2 === a[i].password) {
            alert(`登录成功，具体用户信息如下：

                     city: ${arr[random].city}
                     money: ${arr[random].money}
                     sex: ${arr[random].sex}
                     userName: ${arr[random].userName}
                     
             `)
            return 
          } else {
            let action = +prompt(`
               账户不存在：
               1.注册账号
               2.直接退出
               `)
            if (action === 1) {
              let obj = {}
              let uname = prompt('请输入一个用户名')
              let pass = prompt('请输入一个密码')
              obj.userName = uname
              obj.password = pass
              loginList.push(obj)
              alert('你已经成功注册，直接去登录')
              const user= prompt('请输入用户名')
              const word = prompt('请输入用户密码')
              alert(`登录成功，具体用户信息如下：

                   city: ${arr[random].city}
                   money: ${arr[random].money}
                   sex: ${arr[random].sex}
                   userName: ${arr[random].userName}

                `)
             return
              if(user !== uname && word !== pass) {
                alert('再次输错，已无机会，直接推、退出了')
              }
            }
            if (action === 2) {
              return
            }
          }
        }
      }

      fn(loginList, userInfo)
    </script>
</body>

</html>